import java.util.Date;


/**
 * 所有任务接口
 * 其他任务必须继承该类
 * 
 * @author Xinz
 *
 */
public abstract class Task implements Runnable {

	/**
	 * 产生时间
	 */
	private Date generateTime = null;
	/**
	 * 提交执行时间
	 */
	private Date submitTime = null;
	/**
	 * 开始执行时间
	 */
	private Date beginExxcuteTime = null;
	/**
	 * 执行完成时间
	 */
	private Date finishTime = null;
	
	private long taskId;
	
	public Task() {
		this.setGenerateTime(new Date());
	}
	
	@Override
	public void run() {
		// 相关执行代码
//		beginTransaction();
		// 执行过程中可能产生新的任务subTask = taskCore();
//		commitTransction();
		// 增加新产生的任务 ThreadPool.getInstance().batchAddTask(taskCore());
	}
	
	/**
	 * 所有任务的核心 所有特别的业务逻辑执行之处
	 * @return
	 * @throws Exception
	 */
	public abstract Task[] taskCore() throws Exception;
	/**
	 * 是否用到数据库
	 * @return
	 */
	protected abstract boolean useDb();
	/**
	 * 是否需要立即执行
	 * @return
	 */
	protected abstract boolean needExecuteImmediate();
	/**
	 * 任务信息
	 * @return
	 */
	public abstract String info();

	public Date getGenerateTime() {
		return generateTime;
	}

	public void setGenerateTime(Date generateTime) {
		this.generateTime = generateTime;
	}

	public Date getSubmitTime() {
		return submitTime;
	}

	public void setSubmitTime(Date submitTime) {
		this.submitTime = submitTime;
	}

	public Date getBeginExxcuteTime() {
		return beginExxcuteTime;
	}

	public void setBeginExxcuteTime(Date beginExxcuteTime) {
		this.beginExxcuteTime = beginExxcuteTime;
	}

	public Date getFinishTime() {
		return finishTime;
	}

	public void setFinishTime(Date finishTime) {
		this.finishTime = finishTime;
	}

	public long getTaskId() {
		return taskId;
	}

	public void setTaskId(long taskId) {
		this.taskId = taskId;
	}

}
